package com.dkd.interfaceinfo.service.impl;

import java.util.List;
import com.dkd.common.utils.DateUtils;
import com.dkd.common.utils.SecurityUtils;
import com.dkd.ypclientsdk.client.YpApiClient;
import com.dkd.ypclientsdk.model.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dkd.interfaceinfo.mapper.InterfaceInfoMapper;
import com.dkd.interfaceinfo.domain.InterfaceInfo;
import com.dkd.interfaceinfo.service.IInterfaceInfoService;

import javax.annotation.Resource;

/**
 * 接口信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-03
 */
@Service
public class InterfaceInfoServiceImpl implements IInterfaceInfoService 
{
    @Autowired
    private InterfaceInfoMapper interfaceInfoMapper;

    @Autowired
    private YpApiClient ypApiClient;
    /**
     * 查询接口信息
     * 
     * @param id 接口信息主键
     * @return 接口信息
     */
    @Override
    public InterfaceInfo selectInterfaceInfoById(Long id)
    {
        return interfaceInfoMapper.selectInterfaceInfoById(id);
    }

    /**
     * 查询接口信息列表
     * 
     * @param interfaceInfo 接口信息
     * @return 接口信息
     */
    @Override
    public List<InterfaceInfo> selectInterfaceInfoList(InterfaceInfo interfaceInfo)
    {
        return interfaceInfoMapper.selectInterfaceInfoList(interfaceInfo);
    }

    /**
     * 新增接口信息
     * 
     * @param interfaceInfo 接口信息
     * @return 结果
     */
    @Override
    public int insertInterfaceInfo(InterfaceInfo interfaceInfo)
    {
        interfaceInfo.setStatus(0L);
        long userId = SecurityUtils.getUserId();
        interfaceInfo.setUserId(userId);
        interfaceInfo.setCreateTime(DateUtils.getNowDate());
        return interfaceInfoMapper.insertInterfaceInfo(interfaceInfo);
    }

    /**
     * 修改接口信息
     * 
     * @param interfaceInfo 接口信息
     * @return 结果
     */
    @Override
    public int updateInterfaceInfo(InterfaceInfo interfaceInfo)
    {
        User user = new User();
        user.setUsername("yp");
//        String userNameByPost = ypApiClient.getUserNameByPost(user);
//
//        if(StringUtils.isBlank(userNameByPost)){
//            return  0;
//
//        }
        interfaceInfo.setUpdateTime(DateUtils.getNowDate());


        return interfaceInfoMapper.updateInterfaceInfo(interfaceInfo);
    }

    /**
     * 批量删除接口信息
     * 
     * @param ids 需要删除的接口信息主键
     * @return 结果
     */
    @Override
    public int deleteInterfaceInfoByIds(Long[] ids)
    {
        return interfaceInfoMapper.deleteInterfaceInfoByIds(ids);
    }

    /**
     * 删除接口信息信息
     * 
     * @param id 接口信息主键
     * @return 结果
     */
    @Override
    public int deleteInterfaceInfoById(Long id)
    {
        return interfaceInfoMapper.deleteInterfaceInfoById(id);
    }
}
